﻿using System;
using UIFramwork.Factory.Component;
using UIFramwork.Pool;
using UnityEngine;


namespace UIFramwork.Factory
{
    /// <summary>
    /// UI配件属性工厂
    /// </summary>
    public class UIComponentFactory
    {
        public static GameObject GetMask()
        {
            Type type = typeof(UIMask);

            bool isGet = UIAssetsPool.TryGetUnitPool(type, out var output);
            if (!isGet)
            {
                UIMask mask = new GameObject("[部件] 遮罩").AddComponent<UIMask>();
                mask.Init();

                output = UIAssetsPool.CreateUnitPool(type, mask.gameObject);
            }

            return output.Get();
        }

        public static GameObject GetBlock()
        {
            Type type = typeof(UIBlock);

            bool isGet = UIAssetsPool.TryGetUnitPool(type, out var output);
            if (!isGet)
            {
                GameObject prefab = new GameObject("[部件] 阻挡");
                UIBlock mask = prefab.AddComponent<UIBlock>();

                prefab.transform.localScale = Vector3.zero;

                output = UIAssetsPool.CreateUnitPool(type, prefab);
            }

            return output.Get();
        }
    }
}
